package com.machine.filling.function.set.versionCheck;

import android.content.Context;

import com.google.gson.Gson;
import com.machine.filling.db.dao.ClientInfoDao;
import com.machine.filling.net.http.network.APIHttpManager;
import com.machine.filling.net.http.network.BaseHttpStringCallback;
import com.machine.filling.net.ws.response.WsResVersionCheckBean;
import com.machine.filling.util.CustomToast;
import com.machine.filling.util.SdkUtils;

import okhttp3.Call;

/**
 * Created by Administrator on 2018/3/10 0010.
 */

public class VersionCheckPresenter implements VersionCheckContract.Presenter{
    private Context mContext;
    private VersionCheckContract.View mView;
    private static final String TAG = "VersionCheckPresenter";

    public VersionCheckPresenter(Context mContext, VersionCheckContract.View mView) {
        this.mContext = mContext;
        this.mView = mView;
    }

    @Override
    public void start() {

    }

    @Override
    public void distoryContext() {

    }

    @Override
    public void checkVersion() {
        String token = ClientInfoDao.getInstance().getModleByDeviceNum().getToken();
        String machineId = ClientInfoDao.getInstance().getModleByDeviceNum().getMachineId();
        mView.showProgress(null);
        APIHttpManager.getInstance().checkeAPKVersion(token, machineId, new BaseHttpStringCallback() {
            @Override
            public void onSuccess(Call call, String result) {
                WsResVersionCheckBean bean = new Gson().fromJson(result,WsResVersionCheckBean.class);
                mView.showUpdateApk(bean);

            }

            @Override
            public void onFailed(String errorCode, String errorMsg, Exception exception) {
                CustomToast.showToast(mContext,errorCode);
            }

            @Override
            public void onFinished() {
                mView.hideProgress();
            }
        });
    }
}
